Today, in the article “Sinusoidal Frequency Meter using Arduino” you will learn how to measure the frequency of sinusoidal wave using arduino. With the purposed design one can measure sinusoidal frequency of about 20 Hz to 5KHz.
Features of Sinusoidal Frequency Meter using Arduino
- Rectifier is used thus digital in natures.
- Optocoupler is used in order to isolate frequency circuit and control circuit and this optocoupler is also used to generate spike.
- Dedicated LCD for displaying frequency.
Circuit Description of Sinusoidal Frequency Meter using Arduino
Circuit of sinusoidal frequency meter using arduino shown in figure 1. It is designed around arduino board, bridge rectifier, 16×2 LCD, 4N35 optocoupler and few resistors as shown in circuit diagram. (Any version of arduino can be used, here in this prototype I am using arduino nano). The signal to be measured is given to connector CON1.
The signal is rectified using bridge rectifier (BR1) and is given to input of optocoupler IC (pin 1 and 2) as shown in circuit diagram. In between bridge rectifier and optocoupler we have to use a current limiting resistor. So, let’s calculate the value of current limiter resistor. You can also check the article on how to interface opto coupler and arduino.
From the datasheet of 4N35
Forward voltage of 4N35 (input LED) = 1.2V
Forward current of 4N35 (Input Led) = 10mA
For this prototype we are using 1K resistor, the voltage drops across this resistor (VR) = R x I = 1000 x 10 x 10-3 = 10V.
Therefore, maximum amplitude of sinusoidal given to measure when we are using 1K resistor = 10V + 1.2V = 11.2V. But if you wish to measure higher amplitude frequency you have to increase the value of resistor too.
The output of bridge rectifier is pulsating voltage which ON and OFF the internal LED of optocoupler IC. As a result, it produces spike voltage. Arduino read this voltage. The generated spike is double the number of supplied signal because we are using bridge rectifier. Bridge rectifier convert one complete sinewave (positive half wave and negative half wave) into two positive half waves. Thus, the spike is double the number of measuring frequency.
The collector or pin 5 of 2N35 optocoupler is connected to arduino 5V pin through a 10K resistor and this pin is also connected to arduino digital pin D5. Where emitter (pin 4) is connected to arduino ground as shown in circuit diagram. When internal LED of 2N35 is glowing, internal transistor of 2N35 start to connect as a result it is connected to ground thus no voltage is available at arduino pin. But when internal LED of 2N35 is not glowing voltage is available at digital pin 5.
Arduino count this cycle and display over LCD. In one full cycle of sine wave optocoupler conduct two times as a result arduino read this voltage twice.
LCD is interfacing to arduino in higher order data mode. From circuit diagram we conclude that only data pin D4 – D7 of LCD is connected to arduino for data where RS and E pin of LCD is also connected to arduino in order to enable and set reset of LCD. Pin 15 of LCD is connected to +5V supply of arduino through a current limiting resistor where pin 16 is connected to ground.
Check out the making video of How to interface LCD with arduino.
Software Code: Software code is written in arduino programming language and compiled using arduino IDE. Here we are using Timer for fast processing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 10, 9, 8, 7); //(RS,EN,D4,D5,D6,D7) unsigned int count; unsigned int getCount() { TCCR1B = 0 ; count = TCNT1; TCNT1 = 0; bitSet(TCCR1B , CS12); bitSet(TCCR1B , CS11); bitSet(TCCR1B , CS10); return count; } void setup() { Serial.begin(9600); lcd.begin(16, 2); digitalWrite(5, HIGH); TCCR1A = 0; getCount(); } void loop() { lcd.clear(); delay(1000); lcd.print("Frequency:"); lcd.setCursor(0, 1); lcd.print(getCount()/2); lcd.print(" Hz "); } |